/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_frtask_add.c                                     */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/18 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frlog.h"
#include "frmem.h"
#include "frlist.h"
#include "conntrack.h"
#include "frame.h"
#include "frtask_mng.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}
extern Frlist_header g_lst_hdr_task;

static void case1(void)
{
    Conntrack *p_st_ct = NULL;
    int i_ret = 0;

    i_ret = frtask_add(p_st_ct);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);
    return;

}

static void case2(void)
{
    Conntrack *p_st_ct = NULL;
    int i_ret = 0;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct, 0x00, sizeof(Conntrack));

    frtask_mng_init();

    i_ret = frtask_add(p_st_ct);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    CU_ASSERT_EQUAL(g_lst_hdr_task.size,1);

    frtask_mng_destory();
    frfree(p_st_ct);
    return;

}

static void case3(void)
{
    Conntrack *p_st_ct1 = NULL;
    Conntrack *p_st_ct2 = NULL;
    int i_ret = 0;

    frtask_mng_init();

    p_st_ct1 = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct1, 0x00, sizeof(Conntrack));
    i_ret = frtask_add(p_st_ct1);

    p_st_ct2 = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct2, 0x00, sizeof(Conntrack));
    i_ret = frtask_add(p_st_ct2);


    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    CU_ASSERT_EQUAL(g_lst_hdr_task.size,2);

    frtask_mng_destory();
    frfree(p_st_ct1);
    frfree(p_st_ct2);
    return;

}

static void case4(void)
{
    Conntrack *p_st_ct1 = NULL;
    Conntrack *p_st_ct2 = NULL;
    Conntrack *p_st_ct3 = NULL;
    int i_ret = 0;


    frtask_mng_init();

    p_st_ct1 = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct1, 0x00, sizeof(Conntrack));
    i_ret = frtask_add(p_st_ct1);

    p_st_ct2 = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct2, 0x00, sizeof(Conntrack));
    i_ret = frtask_add(p_st_ct2);

    p_st_ct3 = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct3, 0x00, sizeof(Conntrack));
    i_ret = frtask_add(p_st_ct3);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    CU_ASSERT_EQUAL(g_lst_hdr_task.size,2);

    frtask_mng_destory();
    frfree(p_st_ct1);
    frfree(p_st_ct2);
    frfree(p_st_ct3);
    return;

}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t_frtask_add 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);
   	CU_add_test(pSuite, "case2", case2);
   	CU_add_test(pSuite, "case3", case3);
   	CU_add_test(pSuite, "case4", case4);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}